import apolloClient from './graphReuqest'
import gql from 'graphql-tag'
import { productApi } from '@/config'
import axios from 'axios'

// fundRaiseType入参   graphQlParams出参
export function exportFundData({ fundRaiseType, graphQlParams, statusList, fundSysCode, fundType, fundLike, selectType, manageStatus, personLiableId, checkLiableId }, page) { // 导出指定基金数据
	return apolloClient.query({
		query: gql`query {
			getFundDetailInfoV1(
				fundInfoVO: 
				{
				manageStatus:${manageStatus ? `"${manageStatus}"` : null},
				fundRaiseType:"${fundRaiseType || ''}",
				fundSysCode:"${fundSysCode || ''}",
				fundLike:"${fundLike || ''}",
				fundType:"${fundType || ''}",
				selectType:"${selectType || ''}",
				sequence:"${new Date().getMilliseconds()}",
				status:"${statusList ? [...statusList].join(',') : ''}",
				personLiableIds:"${personLiableId || ''}",
				checkLiableIds:"${checkLiableId || ''}",
				},
				igwPage:${page || null}
				){
					fundDetailGraphqlDTOs{
						${graphQlParams}
					},
					total
			}
		 }
		`
	})
}

export function exportFundFile(param, page) { // 导出基金文件
	const obj = {
		data: {
			body: param || {},
			page: page || {}
		},
		code: 0,
		msg: 'ok',
		serialNo: '',
		success: true
	}
	return new Promise((resolve) => {
		axios({
			method: 'post',
			url: `/${productApi}/fund_file/export_file/v1`,
			data: obj,
			responseType: 'blob',
			timeout: 3000000000
		}).then(res => {
			if (res.headers['content-disposition']) {
				resolve(res.data)
			} else {
				resolve({ msg: '暂无产品文件' })
			}
		})
	})
}
